/**
 * 此文件用于填写相关辅助方法的接口，例如 获取手机号等等
 */
import type {
  GetTenantIdByLocationParams,
  GetTenantIdByLocationResult
} from '@/api/sys/model/paasModel'
import { http } from '@/utils'

enum Api {
  newGetPhone = '/paas/paasuser/getWxNewPhoneNoInfo',
  getPhone = '/paas/paasuser/getWxMiniUserPhone',
  getTenantId = '/paas/appClient/getTenantByLocation'
}

export interface NewGetPhoneParams {
  code: string
  miniAppId: string
}

export interface GetPhoneParams {
  encryptedData: string
  iv: string
  wxAppId: string
}

export interface GetPhoneNumberResult {
  /**
   * 城市CODE
   */
  countryCode: string
  /**
   * 手机号码
   */
  phoneNumber: string
  /**
   * 带前缀的手机号码
   */
  purePhoneNumber: string
}

// 新版接口 获取手机号码
export function getWxNewPhoneNoInfoApi(query: NewGetPhoneParams) {
  return http.get<GetPhoneNumberResult>(Api.newGetPhone, query, {
    ignoreCheckToken: true
  })
}

// 旧版兼容接口 获取手机号码
export function getWxMiniUserPhoneApi(data: GetPhoneParams) {
  return http.post<GetPhoneNumberResult>(Api.getPhone, data, {
    ignoreHandleError: true
  })
}

// 根据地理位置获取租户Id
export function getTenantIdByLocationApi(data: GetTenantIdByLocationParams) {
  return http.get<GetTenantIdByLocationResult>(Api.getTenantId, data)
}
